Skip to contentSkip to conversation

Change in openvpn[master]: socket: don't transfer bind family to socket in case of ANY address

Openvpn-devel In review ordex (Code Review) 2 participants 10 messages Mar 12, 2025 – May 19, 2025 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1741816346000.I27f305d3ae9bf650bab409e99173688d9f88ab65@...2715...

#1 lore raw

Attention is currently required from: flichtenheld, plaisthos.

Hello plaisthos, flichtenheld,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/907?usp=email

to review the following change.

Change subject: socket: don't transfer bind family to socket in case of ANY address
......................................................................

socket: don't transfer bind family to socket in case of ANY address

With the introduction of multisocket, we need to transfer the AI family of the bound address to the socket, as it may differ from what was set globally.

However, this operation makes sense only when getaddrinfo() for bind is performed on a non-empty hostname.
An empty hostname (ANY) may return AF_INET which will break following connection attempts to v6 only remotes.

Change-Id I27f305d3ae9bf650bab409e99173688d9f88ab65

---
M src/openvpn/socket.c

1 file changed, 11 insertions(+), 3 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/07/907/1

src/openvpn/socket.c +11 -3
index 6b32e30..808870b 100644
@@ -1724,9 +1724,17 @@
                 gai_strerror(status));
         }
 
-        /* the resolved 'local entry' might have a different family than what
-         * was globally configured */
-        sock->info.af = sock->info.lsa->bind_local->ai_family;
+        /* the resolved family makes sense only if the host is not ANY,
+         * otherwise getaddrinfo() may return v4 and break connections
+         * to v6 only remotes
+         */
+        if (sock->local_host)
+        {
+            /* the resolved 'local entry' might have a different family than
+             * what was globally configured
+             */
+            sock->info.af = sock->info.lsa->bind_local->ai_family;
+        }
     }
 
     gc_free(&gc);

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/907?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I27f305d3ae9bf650bab409e99173688d9f88ab65
Gerrit-Change-Number: 907
Gerrit-PatchSet: 1
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, ordex.

plaisthos has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/907?usp=email )

Change subject: socket: don't transfer bind family to socket in case of ANY address
......................................................................

Patch Set 1:

(1 comment)

File src/openvpn/socket.c:

http://gerrit.openvpn.net/c/openvpn/+/907/comment/ccda8104_5599096a :
PS1, Line 1730: */
This comment is hard to understand without the context of the commit. Especially I am not sure the "the is not ANY" part means. And should getaddrinfo be openvpn_getaddrinfo?

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/907?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I27f305d3ae9bf650bab409e99173688d9f88ab65
Gerrit-Change-Number: 907
Gerrit-PatchSet: 1
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Mon, 17 Mar 2025 16:09:36 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment

#3 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/907?usp=email )

Change subject: socket: don't transfer bind family to socket in case of ANY address
......................................................................

Patch Set 1:

(1 comment)

File src/openvpn/socket.c:

http://gerrit.openvpn.net/c/openvpn/+/907/comment/0acac9c8_37c67e42 :
PS1, Line 1730: */

Quoted 1 line

This comment is hard to understand without the context of the commit. […]

ANY was meant to be either INADDR_ANY or IN6ADDR_ANY and represents 0.0.0.0 or ::
I can make this more explicit and add more context to the comment.

Regarding getaddrinfo(), I was truly referring to the syscall, but I understand it can be confusing since it's hidden one layer below.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/907?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I27f305d3ae9bf650bab409e99173688d9f88ab65
Gerrit-Change-Number: 907
Gerrit-PatchSet: 1
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Mon, 17 Mar 2025 20:54:22 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: plaisthos <[email protected]...>
Gerrit-MessageType: comment

#4 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/907?usp=email )

Change subject: socket: don't transfer bind family to socket in case of ANY address
......................................................................

Patch Set 1:

(1 comment)

File src/openvpn/socket.c:

http://gerrit.openvpn.net/c/openvpn/+/907/comment/a5cb1f54_3afcb853 :
PS1, Line 1730: */

Quoted 1 line

ANY was meant to be either INADDR_ANY or IN6ADDR_ANY and represents 0.0.0.0 or :: […]

Done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/907?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I27f305d3ae9bf650bab409e99173688d9f88ab65
Gerrit-Change-Number: 907
Gerrit-PatchSet: 1
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 18 Mar 2025 03:32:36 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: plaisthos <[email protected]...>
Comment-In-Reply-To: ordex <[email protected]...>
Gerrit-MessageType: comment

#5 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

Hello flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/907?usp=email

to look at the new patch set (#2).

Change subject: socket: don't transfer bind family to socket in case of ANY address
......................................................................

socket: don't transfer bind family to socket in case of ANY address

With the introduction of multisocket, we need to transfer the AI family of the bound address to the socket, as it may differ from what was set globally.

However, this operation makes sense only when getaddrinfo() for bind is performed on a non-empty hostname.
An empty hostname (ANY) may return AF_INET which will break following connection attempts to v6 only remotes.

Change-Id I27f305d3ae9bf650bab409e99173688d9f88ab65

---
M src/openvpn/socket.c

1 file changed, 13 insertions(+), 3 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/07/907/2

src/openvpn/socket.c +13 -3
index 6b32e30..be7395d 100644
@@ -1724,9 +1724,19 @@
                 gai_strerror(status));
         }
 
-        /* the resolved 'local entry' might have a different family than what
-         * was globally configured */
-        sock->info.af = sock->info.lsa->bind_local->ai_family;
+        /* the address family returned by openvpn_getaddrinfo() should be
+         * taken into consideration only if we really passed an hostname
+         * to resolve. Otherwise its value is not useful to us and may
+         * actually break our socket, i.e. when it returns AF_INET
+         * but our remote is v6 only.
+         */
+        if (sock->local_host)
+        {
+            /* the resolved 'local entry' might have a different family than
+             * what was globally configured
+             */
+            sock->info.af = sock->info.lsa->bind_local->ai_family;
+        }
     }
 
     gc_free(&gc);

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/907?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I27f305d3ae9bf650bab409e99173688d9f88ab65
Gerrit-Change-Number: 907
Gerrit-PatchSet: 2
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset

#6 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, ordex.

plaisthos has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/907?usp=email )

Change subject: socket: don't transfer bind family to socket in case of ANY address
......................................................................

Patch Set 2: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/907?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I27f305d3ae9bf650bab409e99173688d9f88ab65
Gerrit-Change-Number: 907
Gerrit-PatchSet: 2
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: ordex <[email protected]...>
Gerrit-Comment-Date: Tue, 25 Mar 2025 08:56:01 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#7 lore raw

PATCH v2 1/1 socket: don't transfer bind family to socket in case of ANY address

In reply to a message not in the archive

From: Antonio Quartulli <[email protected]...>

With the introduction of multisocket, we need to transfer the AI family of the bound address to the socket, as it may differ from what was set globally.

However, this operation makes sense only when getaddrinfo() for bind is performed on a non-empty hostname.
An empty hostname (ANY) may return AF_INET which will break following connection attempts to v6 only remotes.

Change-Id I27f305d3ae9bf650bab409e99173688d9f88ab65

---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/907
This mail reflects revision 2 of this Change.

Acked-by according to Gerrit (reflected above):
Arne Schwabe <[email protected]...>

src/openvpn/socket.c +13 -3
index 6b32e30..be7395d 100644
@@ -1724,9 +1724,19 @@
                 gai_strerror(status));
         }
 
-        /* the resolved 'local entry' might have a different family than what
-         * was globally configured */
-        sock->info.af = sock->info.lsa->bind_local->ai_family;
+        /* the address family returned by openvpn_getaddrinfo() should be
+         * taken into consideration only if we really passed an hostname
+         * to resolve. Otherwise its value is not useful to us and may
+         * actually break our socket, i.e. when it returns AF_INET
+         * but our remote is v6 only.
+         */
+        if (sock->local_host)
+        {
+            /* the resolved 'local entry' might have a different family than
+             * what was globally configured
+             */
+            sock->info.af = sock->info.lsa->bind_local->ai_family;
+        }
     }
 
     gc_free(&gc);
#8 lore raw

[Openvpn-devel] [PATCH applied] Re: socket: don't transfer bind family to socket in case of ANY address

This was +2'ed long ago, but got left rotting due to "I need to find a meaningful test case"... well, I give up on this, because this is all very obscure corner cases (setting lport != 0, but not setting a --local address to bind to, and the OS serving us a v6 ANY, breaking connection to a v4 host - which would otherwise work just fine on a v6 dual-stack socket).

Arguably what the patch does is the right behaviour - if no --local address (or host) was specified, do not override use the address family from --proto with the one from --local. *Iff* a --local hostname or explicit v4/v6 address was specified, then it makes no sense to query "for that other family" (this path is unchanged).

Since Arne and the Android client was bitten most by the "lport -> bind" change, and gave his +2 in gerrit, this is all we need :-)

Tested on FreeBSD and Linux, t_client with lots of v4/v6 remotes...

Your patch has been applied to the master branch.

commit c319dcf048c56098a6aba142e76166684ff5ab12

Author: Antonio Quartulli
Date:   Tue Mar 25 10:01:15 2025 +0100
     socket: don't transfer bind family to socket in case of ANY address

     Signed-off-by: Antonio Quartulli <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg31235.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#9 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#3) to the change originally created by ordex. ( http://gerrit.openvpn.net/c/openvpn/+/907?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by plaisthos

Change subject: socket: don't transfer bind family to socket in case of ANY address
......................................................................

socket: don't transfer bind family to socket in case of ANY address

With the introduction of multisocket, we need to transfer the AI family of the bound address to the socket, as it may differ from what was set globally.

However, this operation makes sense only when getaddrinfo() for bind is performed on a non-empty hostname.
An empty hostname (ANY) may return AF_INET which will break following connection attempts to v6 only remotes.

Change-Id I27f305d3ae9bf650bab409e99173688d9f88ab65

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg31235.html

---
M src/openvpn/socket.c

1 file changed, 13 insertions(+), 3 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/07/907/3

src/openvpn/socket.c +13 -3
index 34a049e..93d793b 100644
@@ -1741,9 +1741,19 @@
                 gai_strerror(status));
         }
 
-        /* the resolved 'local entry' might have a different family than what
-         * was globally configured */
-        sock->info.af = sock->info.lsa->bind_local->ai_family;
+        /* the address family returned by openvpn_getaddrinfo() should be
+         * taken into consideration only if we really passed an hostname
+         * to resolve. Otherwise its value is not useful to us and may
+         * actually break our socket, i.e. when it returns AF_INET
+         * but our remote is v6 only.
+         */
+        if (sock->local_host)
+        {
+            /* the resolved 'local entry' might have a different family than
+             * what was globally configured
+             */
+            sock->info.af = sock->info.lsa->bind_local->ai_family;
+        }
     }
 
     gc_free(&gc);

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/907?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I27f305d3ae9bf650bab409e99173688d9f88ab65
Gerrit-Change-Number: 907
Gerrit-PatchSet: 3
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset

#10 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/907?usp=email )

Change subject: socket: don't transfer bind family to socket in case of ANY address
......................................................................

socket: don't transfer bind family to socket in case of ANY address

With the introduction of multisocket, we need to transfer the AI family of the bound address to the socket, as it may differ from what was set globally.

However, this operation makes sense only when getaddrinfo() for bind is performed on a non-empty hostname.
An empty hostname (ANY) may return AF_INET which will break following connection attempts to v6 only remotes.

Change-Id I27f305d3ae9bf650bab409e99173688d9f88ab65

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg31235.html

---
M src/openvpn/socket.c

1 file changed, 13 insertions(+), 3 deletions(-)
src/openvpn/socket.c +13 -3
index 34a049e..93d793b 100644
@@ -1741,9 +1741,19 @@
                 gai_strerror(status));
         }
 
-        /* the resolved 'local entry' might have a different family than what
-         * was globally configured */
-        sock->info.af = sock->info.lsa->bind_local->ai_family;
+        /* the address family returned by openvpn_getaddrinfo() should be
+         * taken into consideration only if we really passed an hostname
+         * to resolve. Otherwise its value is not useful to us and may
+         * actually break our socket, i.e. when it returns AF_INET
+         * but our remote is v6 only.
+         */
+        if (sock->local_host)
+        {
+            /* the resolved 'local entry' might have a different family than
+             * what was globally configured
+             */
+            sock->info.af = sock->info.lsa->bind_local->ai_family;
+        }
     }
 
     gc_free(&gc);

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/907?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I27f305d3ae9bf650bab409e99173688d9f88ab65
Gerrit-Change-Number: 907
Gerrit-PatchSet: 3
Gerrit-Owner: ordex <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged